<?php

class Flds {
    public $id = 0;
    public $floor_id = 0;
    public $tbl = '';
    public $sen = '';
    public $use_timelimit = '';
    public $time_min = '';
    public $time_max = '';
    public $time_shift = '';
    public $whatsum = '';


    private static $fields;

    private $data = array();
//-------------------------------------------


    public function __set($name, $value) {
        $this->data[$name] = $value;
    }

    public function __get($name) {
        return Arr::getValue($this->data, $name);
    }

    public function __construct($array=array()) {
        if (!is_array(self::$fields)) {
            $name = get_class($this);
            self::$fields = array_keys(get_class_vars($name));
        }

        $this->setFromArray($array);
    }

//--------------------------------------------

    public function setFromArray($array=array()) {
        if (!is_array($array)) return;
        foreach ($array as $key => $val) {
            $this->$key = $val;
        }
    }

    public function asArray() {
        $out = array();
        foreach (self::$fields as $key) {
            $out[$key] = $this->$key;
        }
        return $out;
    }

    public function fields() {
        return self::$fields;
    }

    public function getSenForQuery() {
        $arr = explode(',', trim($this->sen));
        $out = array();
        if (is_array($arr)) foreach ($arr as $s) $out[] = "'$s'";

        return join(',', $out);
    }

}


?>